home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Dialectic 1.2 / source / Dialectic ƒ / Dialectic code / dialectic graphics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.9 KB  |  156 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        dialectic graphics.c
  4.  
  5. Purpose:    This module handles drawing the clipboard contents into
  6.             a window.
  7.  
  8.  
  9. Dialectic -=- dialect text conversion extraordinare
  10. Copyright ©1994, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "graphics.h"
  30. #include "environment.h"
  31. #include "dialectic graphics.h"
  32. #include "util.h"
  33.  
  34. /* internal procedures for dialectic graphics.c only */
  35. void SetupTheClipboardWindow(WindowDataHandle theData);
  36. void InitializeTheClipboardWindow(WindowDataHandle theData);
  37. void OpenTheClipboardWindow(WindowDataHandle theData);
  38. void SuspendTheClipboardWindow(WindowDataHandle theData);
  39. void ResumeTheClipboardWindow(WindowDataHandle theData);
  40. void DrawTheClipboardWindow(void);
  41.  
  42. int ClipboardWindowDispatch(ExtendedWindowDataHandle theData, int theMessage, unsigned long misc)
  43. {
  44.     switch (theMessage)
  45.     {
  46.         case kUpdate:
  47.             DrawTheClipboardWindow();
  48.             return kSuccess;
  49.             break;
  50.         case kInitialize:
  51.             InitializeTheClipboardWindow(theData);
  52.             return kSuccess;
  53.         case kOpen:
  54.             OpenTheClipboardWindow(theData);
  55.             return kSuccess;
  56.             break;
  57.         case kSuspend:
  58.             SuspendTheClipboardWindow(theData);
  59.             return kSuccess;
  60.             break;
  61.         case kResume:
  62.             ResumeTheClipboardWindow(theData);
  63.             return kSuccess;
  64.             break;
  65.         case kStartup:
  66.             SetupTheClipboardWindow(theData);
  67.             return kSuccess;
  68.             break;
  69.     }
  70.     
  71.     return kFailure;
  72. }
  73.  
  74. void SetupTheClipboardWindow(WindowDataHandle theData)
  75. {
  76.     unsigned char    *titleStr="\pClipboard";
  77.     
  78.     (**theData).windowWidth=350;
  79.     (**theData).windowHeight=200;
  80.     (**theData).windowBounds.top=
  81.         screenBits.bounds.bottom-(**theData).windowHeight-10;
  82.     (**theData).windowBounds.left=10;
  83.     (**theData).windowType=noGrowDocProc;
  84.     (**theData).hasCloseBox=TRUE;
  85.     Mymemcpy((**theData).windowTitle, titleStr, titleStr[0]+1);
  86. }
  87.  
  88. void InitializeTheClipboardWindow(WindowDataHandle theData)
  89. {
  90.     (**theData).initialTopLeft.v=(**theData).windowBounds.top-9;
  91.     (**theData).initialTopLeft.h=(**theData).windowBounds.left;
  92. }
  93.  
  94. void OpenTheClipboardWindow(WindowDataHandle theData)
  95. {
  96.     (**theData).offscreenNeedsUpdate=TRUE;
  97. }
  98.  
  99. void SuspendTheClipboardWindow(WindowDataHandle theData)
  100. {
  101.     HideWindow(gTheWindow[(**theData).windowIndex]);
  102. }
  103.  
  104. void ResumeTheClipboardWindow(WindowDataHandle theData)
  105. {
  106.     OpenTheWindow(kClipboard);
  107. }
  108.  
  109. void DrawTheClipboardWindow(void)
  110. {
  111.     GrafPtr            curPort;
  112.     Handle            inputHandle;
  113.     unsigned long    i;
  114.     unsigned long    theSize;
  115.     int                col, row;
  116.     Boolean            notDoneYet;
  117.     unsigned char    theChar;
  118.     int                w, h;
  119.     
  120.     GetPort(&curPort);
  121.     
  122.     EraseRect(&(curPort->portRect));
  123.     w=curPort->portRect.right-curPort->portRect.left;
  124.     h=curPort->portRect.bottom-curPort->portRect.top;
  125.     
  126.     LoadScrap();
  127.     inputHandle=NewHandle(0L);
  128.     if ((theSize=GetScrap(inputHandle, 'TEXT', &i))==noTypeErr)
  129.         return;
  130.     
  131.     TextFont(monaco);
  132.     TextSize(9);
  133.     
  134.     i=0L;
  135.     col=5;
  136.     row=12;
  137.     notDoneYet=TRUE;
  138.     MoveTo(col, row);
  139.     HLock(inputHandle);
  140.     while ((i<theSize) && (notDoneYet))
  141.     {
  142.         theChar=*(unsigned char*)((unsigned long)(*inputHandle)+(i++));
  143.         DrawChar(theChar);
  144.         col+=CharWidth(theChar);
  145.         if ((col>w-5) || (theChar==0x0d))
  146.         {
  147.             col=5;
  148.             row+=12;
  149.             MoveTo(col, row);
  150.             notDoneYet=(row<h-5);
  151.         }
  152.     }
  153.     
  154.     DisposeHandle(inputHandle);
  155. }
  156.